package com.unknowpupil.web.config.swagger;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Classname: Swagger2Configuration
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2019/10/1 17:15
 * @Description:
 * @Version: 1.0
 */
@Configuration
public class Swagger2Configuration {
    @Value("${swaager.config.enabled}")
    private Boolean swaggerEnabled;
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)

                .apiInfo(apiInfo())
                .enable(swaggerEnabled)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.unknowpupil.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("WEB API 文档")
                .description("unknowpupil API 网关接口，http://www.unknowpupil.com/swagger-ui.html")
                .termsOfServiceUrl("http://www.unknowpupil.com")
                .version("1.0.0")
                .build();
    }
}
